package scenic.study.designmode.behaviour_type.responsibility;

import java.util.ArrayList;
import java.util.List;

/**
 * 处理链条
 */
public class Chain implements ExecuteFactor {
    private List<ExecuteFactor> executeFactors = new ArrayList<>();

    private int index;

    public void add(ExecuteFactor executeFactor) {
        executeFactors.add(executeFactor);
    }


    @Override
    public void doDealRequest(Chain chain, Param param) {
        if (index == executeFactors.size()) {
            index = 0;
            return;
        }
        ExecuteFactor executeFactor = executeFactors.get(index);
        index++;
        executeFactor.doDealRequest(this,param);
    }

}
